package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetMealService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 *@AUTHOR:LIUCHAO;
 *@DATE: 2020/9/12 14:10
 */
@RequestMapping("/setmeal")
@RestController
public class SetmealController {

    @Reference
    private SetMealService setMealService;


    @RequestMapping("/getSetmeal")
    public Result findAll(){
        List<Setmeal> setMealList = setMealService.findAll();
        if(setMealList != null && setMealList.size() > 0){
            return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,setMealList);
        }
        return new Result(false,MessageConstant.QUERY_CHECKGROUP_FAIL);
    }

    @RequestMapping("/findById")
    public Result findById( String id){
      /*  Setmeal setmeal=null;
        try{
            setmeal=setMealService.findById(Integer.parseInt(id));
        }catch (Exception e){
            return new Result(false,MessageConstant.DELETE_CHECKITEM_FAIL);
        }
        return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS,setmeal);*/
     Setmeal data=null;
      try{
            data = setMealService.findById2(Integer.parseInt(id));
        }catch (Exception e){
          return new Result(false,MessageConstant.DELETE_CHECKITEM_FAIL);
        }
        return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS,data);
    }
}
